import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Observable} from "rxjs/Observable";
import * as moment from 'moment';
import {PageParamsModel} from "../../../model/common/page-params.model";
import {LoadingService} from "../../../services/common/loading.service";

@Injectable()
export class TeamTeamIncreaseProvider {

    // //mock数据
    public totalMember={
        groupList:[
            {
                unitName: "1组",
                unitCode: "1"
            },
            {
                unitName: "2组",
                unitCode: "2"
            },
            {
                unitName: "3组",
                unitCode: "3"
            },
            {
                unitName: "4组",
                unitCode: "4"
            },
            {
                unitName: "5组",
                unitCode: "5"
            },
            {
                unitName: "6组",
                unitCode: "6"
            },
            {
                unitName: "7组",
                unitCode: "7"
            },
            {
                unitName: "8组",
                unitCode: "8"
            },
            {
                unitName: "9组",
                unitCode: "9"
            },
            {
                unitName: "10组",
                unitCode: "10"
            },
            {
                unitName: "11组",
                unitCode: "11"
            }
        ],
        groupRecruitTarget: {
            totalPoolNum: 584,
            totalCandidateNum: 13,
            totalVirtualNum: 13,
            totalITCNum: 234,
            totalEntryNum: 324
        },
        pageInfo: {
            pageNum: 1,
            pageSize: 10,
            total: 36,
            pages: 1,
            list: [
                {
                    unitName: "1组",
                    unitCode: "1",
                    agentCode: "SH30580",
                    agentName: "水水水水",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "1组",
                    unitCode: "1",
                    agentCode: "SH30581",
                    agentName: "火火火",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "2组",
                    unitCode: "2",
                    agentCode: "SH30582",
                    agentName: "大幅度",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "3组",
                    unitCode: "3",
                    agentCode: "SH30583",
                    agentName: "班干部",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "4组",
                    unitCode: "4",
                    agentCode: "SH30584",
                    agentName: "方便的",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "5组",
                    unitCode: "5",
                    agentCode: "SH30585",
                    agentName: "是是是",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "6组",
                    unitCode: "6",
                    agentCode: "SH30586",
                    agentName: "就好撒",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "7组",
                    unitCode: "7",
                    agentCode: "SH30587",
                    agentName: "快快快",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "8组",
                    unitCode: "8",
                    agentCode: "SH30588",
                    agentName: "而且",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "9组",
                    unitCode: "9",
                    agentCode: "SH30589",
                    agentName: "发生的",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "9组",
                    unitCode: "9",
                    agentCode: "SH30589",
                    agentName: "交换机",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "10组",
                    unitCode: "10",
                    agentCode: "SH30514",
                    agentName: "水电费",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "11组",
                    unitCode: "11",
                    agentCode: "SH30514",
                    agentName: "复合肥",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "3组",
                    unitCode: "3",
                    agentCode: "SH30545",
                    agentName: "十点多",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "4组",
                    unitCode: "4",
                    agentCode: "SH30545",
                    agentName: "规划局",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
                {
                    unitName: "5组",
                    unitCode: "5",
                    agentCode: "SH90512",
                    agentName: "裤脚",
                    poolNum: 0,
                    candidateNum: 13,
                    virtualNum: 300,
                    entryNum: 324,
                    itcnum: 234
                },
            ]
        }
    };

    constructor(public http:HttpClient){}

/**
 * 获取团队增员数据
 */
  getTotalMember(pageInfo:PageParamsModel,loading?:LoadingService):Observable<any> {
    let p:any = {};
    p.pageNum = String(pageInfo.pageNum);
    p.pageSize = String(pageInfo.pageSize);
    if(pageInfo.condition){
        if(pageInfo.condition.groupId!==undefined)p.groupId = pageInfo.condition.groupId;
        p.starttime = pageInfo.condition.starttime?`${moment(pageInfo.condition.starttime).unix()}`:'';
        p.endtime = pageInfo.condition.endtime?`${moment(pageInfo.condition.endtime).endOf('month').unix()}`:'';
    }
    
    return this.http.get('/recruit/target/v1/group',{ params:p });
  }

  /**
   * 获取个人增员数据
   */
  getPersonIncrease(timeParam:any):Observable<any> {
    let url="/recruit/target/v1/view",
        starttime = timeParam.starttime?`${moment(timeParam.starttime).unix()}`:'',
        endtime = timeParam.endtime?`${moment(timeParam.endtime).endOf('month').unix()}`:'';
    url=url+"?starttime="+starttime+"&endtime="+endtime;
    // return this.totalMember; //测试
    return this.http.get(url);
  }

  /**
   * 获取个人增员 -- 人才库总人数
   */
  getTotalTalent():Observable<any> {
    let url="/recruit/target/v1/total";
    return this.http.get(url);
  }
}